 
package com.xbongbong.pro.statistic.model.impl;

import com.xbongbong.paas.enums.DelEnum;
import com.xbongbong.paas.toolbox.util.DateUtil;
import com.xbongbong.pro.domain.dao.ChartCategorySearchDao;
import com.xbongbong.pro.domain.entity.ChartCategorySearchEntity;
import com.xbongbong.pro.statistic.enums.ChartCategoryTypeEnum;
import com.xbongbong.pro.statistic.model.ChartCategoryModel;
import com.xbongbong.pro.statistic.model.ChartCategorySearchModel;
import com.xbongbong.saas.constant.StringConstant;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
* @author autoGen
* @time 2019-01-07 11:13:40
*/
@Service("chartCategorySearchModel")
public class ChartCategorySearchModelImpl implements ChartCategorySearchModel {

	@Resource
	private ChartCategorySearchDao chartCategorySearchDao;

	@Override
	public Integer insert(ChartCategorySearchEntity entity) {
		long now = DateUtil.getInt();
    	entity.setAddTime(now);
    	entity.setUpdateTime(now);
		return chartCategorySearchDao.insert(entity);
	}
	@Override
	public Integer update(ChartCategorySearchEntity entity){
		entity.setUpdateTime((long)DateUtil.getInt());
		
		return chartCategorySearchDao.update(entity);
	}

	@Override
	public Integer save(ChartCategorySearchEntity entity){
		if(entity.getId() == null || entity.getId().equals(0L)) {
			return insert(entity);
		}
		return update(entity);
	}

	@Override
	public Integer getCountsByCategoryId(Long categoryId, String corpid) {
		Map<String, Object> params = new HashMap<>(1 << 4);
		params.put(StringConstant.CORPID, corpid);
		params.put(StringConstant.DEL, DelEnum.NORMAL.getDel());
		params.put("categoryId", categoryId);
		return getEntitysCount(params);
	}

	@Override
	public List<ChartCategorySearchEntity> getByCategoryId(Long categoryId, String corpid) {
		Map<String, Object> params = new HashMap<>(1 << 4);
		params.put(StringConstant.CORPID, corpid);
		params.put(StringConstant.DEL, DelEnum.NORMAL.getDel());
		params.put("categoryId", categoryId);
		return findEntitys(params);
	}

	@Override
	public ChartCategorySearchEntity getById(Long id, String corpid) {
		return chartCategorySearchDao.getById(id, corpid);
	}

	@Override
	public void updateBatch(List<ChartCategorySearchEntity> list, String corpid) {
		chartCategorySearchDao.updateBatch(list, corpid);
	}
	@Override
	public void insertBatch(List<ChartCategorySearchEntity> list) {
		long now = DateUtil.getInt();
		list.forEach(entity -> {
			entity.setAddTime(now);
			entity.setUpdateTime(now);
		});
		chartCategorySearchDao.insertBatch(list);
	}


	@Override
	public List<ChartCategorySearchEntity> findEntitys(Map<String ,Object>  param){
		return chartCategorySearchDao.findEntitys(param);
	}

	@Override
	public Integer getEntitysCount(Map<String ,Object>  param){
		return chartCategorySearchDao.getEntitysCount(param);
	}

	@Override
	public List<ChartCategorySearchEntity> findEntitysWithoutSub(Map<String, Object> param) {
		return chartCategorySearchDao.findEntitys(param);
	}


}

 